package cn.iocoder.yudao.module.mybusiness.service.impl;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.security.core.LoginUser;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.module.mybusiness.domain.BussinessMod;
import cn.iocoder.yudao.module.mybusiness.domain.Facility;
import cn.iocoder.yudao.module.mybusiness.mapper.FacilityMapper;
import cn.iocoder.yudao.module.mybusiness.mapper.ModMapper;
import cn.iocoder.yudao.module.mybusiness.param.ModParam;
import cn.iocoder.yudao.module.mybusiness.service.FcfService;
import cn.iocoder.yudao.module.mybusiness.service.ModService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class ModServiceImpl extends ServiceImpl<ModMapper, BussinessMod> implements ModService {

    @Autowired
    private ModMapper modMapper;

    @Override
    public void delete(Long id) {
        BussinessMod bussinessMod = new BussinessMod();
        bussinessMod.setIsDelete(1);
        bussinessMod.setId(id);
        modMapper.updateById(bussinessMod);
    }

    @Override
    public PageResult<BussinessMod> getList(ModParam modParam) {
        PageResult<BussinessMod> modPageResult = modMapper.selectPage(modParam, new LambdaQueryWrapperX<BussinessMod>()
                .eq(BussinessMod::getIsDelete, 0)
                .likeIfPresent(BussinessMod::getName, modParam.getName())
                .likeIfPresent(BussinessMod::getType,modParam.getType())
                .orderByDesc(BussinessMod::getId));
        return modPageResult;
    }

    @Override
    public void create(BussinessMod mod) {
        LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
        mod.setUserId(loginUser.getId());
        SimpleDateFormat format = new SimpleDateFormat(DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
        mod.setCreateTime(format.format(new Date()));
        modMapper.insert(mod);
    }


}
